package org.jin.samples.web;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.jin.samples.model.vo.ExamScoreVO;
import org.jin.samples.model.vo.ExamUserVO;
import org.jin.samples.model.vo.UserSubjectScoreVO;
import org.jin.samples.page.PagerModel;
import org.jin.samples.service.IScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ScoreController {
	
	@Autowired
	private IScoreService scoreService;
	
	@RequestMapping(value="/score", method = RequestMethod.GET)
	public String score(Model model, HttpSession session) throws Exception{
		ExamUserVO vo = (ExamUserVO) session.getAttribute("examUser");
		String id = vo.getUserId();
		PagerModel<UserSubjectScoreVO> list = scoreService.findAllSubjectScore(id);
		model.addAttribute("score", list);
		return "score/score";
	}
	
	@ResponseBody
	@RequestMapping(value="/showScore", method = RequestMethod.POST)
	public Map<String, Object> showScore(Model model, Integer subjectId, HttpSession session)throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		ExamUserVO vo = (ExamUserVO) session.getAttribute("examUser");
		String userId = vo.getUserId();
		ExamScoreVO scoreVO = scoreService.findScoreByUSId(userId, subjectId);
		map.put("scoreNew", scoreVO);
		return map;	
	}
	
}
